#include <iostream>
#include <string.h>
using namespace std;

class Person{
public:
    Person(const char *name,int age)
    :_name(new char[strlen(name)+1]())
    ,_age(age)
    {
        strcpy(_name,name);
    }

    ~Person(){
        if(_name!=NULL){
            delete[] _name;
            _name=NULL;
        }
    }

    Person(const Person &rhs)
    :_name(new char[strlen(rhs._name)+1]())
    ,_age(rhs._age)
    {
        strcpy(_name,rhs._name);
    }

    Person &operator=(const Person &rhs){
        if(this!=&rhs){
            delete[] _name;
            _name=new char[strlen(rhs._name)+1]();
            strcpy(_name,rhs._name);
            _age=rhs._age;
        }
        return *this;
    }

    void display(){
        cout << "name:" << _name << ",age" << _age << endl;
    }

protected:
    char *_name;
    int _age;
};

class Employee
:public Person{
public:
    Employee(const char *name,int age,const char *department,int salary)
    :Person(name,age)
    ,_department(new char[strlen(department)+1]())
    ,_salary(salary)
    {
        strcpy(_department,department);
    }

    ~Employee(){
        if(_department!=NULL){
            delete[] _department;
            _department=NULL;
        }
    }

    Employee(const Employee &rhs)
    :Person(rhs)
    ,_department(new char[strlen(rhs._department)+1]())
    ,_salary(rhs._salary)
    {
        strcpy(_department,rhs._department);
    }

    Employee &operator=(const Employee &rhs){
        if(this!=&rhs){
            Person::operator=(rhs);
            delete[] _department;
            _department=new char[strlen(rhs._department)+1]();
            strcpy(_department,rhs._department);
            _salary=rhs._salary;
        }
        return *this;
    }

    void display(){
        Person::display();
        cout << "部门：" << _department << ",薪资：" << _salary << endl;
    }

private:
    char *_department;
    int _salary;
};

void test(){
    Employee emp1("张三",20,"开发岗",15000);
    Employee emp2=emp1;
    emp1.display();
    emp2.display();
}

int main()
{
    test();
    return 0;
}

